package com.zm.demo.shoppingmall.gateway.advice;

import com.zm.demo.shoppingmall.common.response.ShoppintMallResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @desc:
 * @author: z01140
 * @date: 2021/5/25 16:50
 */

@Slf4j
@ControllerAdvice
public class WepAdvice {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ShoppintMallResponse exceptionHandler(Exception e){
        log.error("接口调用失败", e);
        return ShoppintMallResponse.response(0,e.getMessage());
    }

//    @ExceptionHandler(value = Exception.class)
//    public ModelAndView myErrorHandler(Exception ex) {
//        ModelAndView modelAndView = new ModelAndView();
//        //指定错误页面的模板页
//        modelAndView.setViewName("error");
//        modelAndView.addObject("msg", ex.getMessage());
//        return modelAndView;
//    }
}
